home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 2 / Atari Mega Archive CD - Volume 2.iso / 8bit / cislib_a / epson.act < prev    next >
Text File  |  1995-04-22  |  9KB  |  443 lines

  1.  
  2.  
  3. ;++++++++++++++++++++++++++++++++++++
  4. ; EPSON/ATASCII PRINT FORMATTER  
  5. ; Prints listed BASIC programs and
  6. ; text using Epson bit mode graphics
  7. ; to print non-ASCII characters
  8. ;
  9. ; With suitable changes to the Epson
  10. ; specific variables immediately  
  11. ; below, this program will work with
  12. ; a number of other graphic printers.
  13. ;
  14. ; (c)1983 Leo G. Laporte
  15. ;         BOX 21248
  16. ;         San Jose, CA 95151
  17. ;         CIS PPN # 70215,1022
  18. ; Placed in public domain 12/8/83.
  19. ;++++++++++++++++++++++++++++++++++++
  20.  
  21. BYTE  rts = [$60],  ; OSA+ bug fix
  22.       bank = $D500  ; Atari DOS bug fix
  23.          
  24.  
  25. MODULE         
  26.  
  27. DEFINE TRUE="1",    
  28.        FALSE="0",              
  29.        BOOL="BYTE",
  30.  
  31.        KEY = "0",
  32.        FILE = "1",
  33.        EPSON = "2",
  34.  
  35.        MAXLINE = "55" ; max # of lines per page
  36.  
  37. ; Epson specific stuff
  38.  
  39. CHAR ARRAY grmode = [4 27 75 8 0], 
  40.            ; initializes bit-mode graphics (ESC K 8 0)
  41.            ; and tells printer that eight graphic
  42.            ; data bytes will follow.
  43.  
  44.            italics_on = [2 27 '4], ; if you have an older Epson w/o italics
  45.            italics_off = [2 27 '5] ; change these strings to another suitable font
  46.            
  47. CHAR       formfeed = [12]
  48.            
  49. ;------------------------------------
  50. ; PROCEDURE DECLARATIONS
  51. ;------------------------------------
  52.  
  53. PROC grprint(CHAR chr)
  54.  
  55. ; does a graphic print of non-ASCII
  56. ; characters
  57.  
  58.   BYTE ARRAY mask =[128 64 32 16 8 4 2 1], ; bit values D7 to D0
  59.              CHARSET = $E000, ; location of character set in ROM
  60.              grdata(8) ; character data array
  61.  
  62.   BYTE offset, ; current character data byte
  63.        bit,    ; current bit in byte
  64.        byt     ; graphic data byte
  65.  
  66.   BOOL bit_set, ; is bit set? flag
  67.        inv_flag ; inverse char?
  68.  
  69.   CARD charloc ; location of character data
  70.  
  71.   ; check for inverse character
  72.  
  73.   IF (chr & 128) THEN
  74.     inv_flag = TRUE
  75.     chr ==& 127     ; strip off inverse bit
  76.   ELSE
  77.     inv_flag = FALSE
  78.   FI
  79.  
  80.   ; find character data in ROM
  81.  
  82.   IF chr < 32 THEN
  83.      charloc = (chr + 64) * 8
  84.   ELSEIF chr > 31 AND chr < 96 THEN
  85.      charloc = (chr - 32) * 8
  86.   ELSE 
  87.      charloc = chr * 8
  88.   FI   
  89.  
  90.   ; rotate char data for Epson
  91.  
  92.   Zero(grdata, 8) ; clear character graphics data
  93.   FOR offset = 0 TO 7 ; step through char data
  94.     DO 
  95.       FOR bit = 0 TO 7
  96.         DO
  97.           bit_set =  CHARSET(charloc + offset) & mask(bit)
  98.             IF inv_flag THEN
  99.               IF bit_set = FALSE THEN
  100.                 grdata(bit) ==+  mask(offset)
  101.               FI
  102.             ELSEIF bit_set THEN
  103.               grdata(bit) ==+  mask(offset)
  104.             FI
  105.         OD
  106.     OD
  107.   
  108.   ; dump character data
  109.  
  110.   PrintD(EPSON, grmode)
  111.   FOR byt = 0 TO 7
  112.     DO     
  113.       IF grdata(byt) = 155 THEN ;prevent sending CR and thereby
  114.         grdata(byt) = 151       ;cancelling graphics mode (only
  115.       FI                        ; occurs during printing of inverse A)
  116.       PutD(EPSON, grdata(byt))
  117.     OD
  118.  
  119. RETURN
  120.  
  121. ;-----------------------------------
  122.  
  123. PROC feed(BYTE lines)
  124.  
  125. ; feeds "lines" lines
  126.  
  127. BYTE i
  128.  
  129.    FOR i = 1 TO lines
  130.      DO
  131.        PutDE(EPSON)
  132.      OD
  133.  
  134. RETURN
  135.  
  136. ;------------------------------------
  137.  
  138. PROC indent(BYTE col)
  139.  
  140. ; tabs to col 
  141.  
  142. BYTE space = [32], i
  143.  
  144. FOR i = 1 TO col
  145.    DO  PutD(EPSON, space)  OD
  146.  
  147. RETURN
  148.  
  149. ;------------------------------------
  150.  
  151. BYTE FUNC PrintTEXT(CHAR ARRAY line)
  152.  
  153. ; prints TEXT input line
  154.  
  155. CHAR eol = [155],
  156.      chr
  157.  
  158. BYTE cnt, col
  159.  
  160. CARD linecnt ; number of lines output
  161.  
  162. cnt = 1   ; current character in line
  163. col  = 0  ; current printer column
  164. linecnt = 0 ; lines printed
  165.  
  166.   chr = line(cnt)
  167.   IF chr = eol THEN 
  168.      PutDE(EPSON)
  169.      RETURN (1)
  170.   FI
  171.  
  172.   WHILE chr <> eol 
  173.   DO                     
  174.  
  175.     IF ; printable character
  176.     (chr > 31 AND chr < 123 AND chr <> 96) THEN
  177.        PutD(EPSON, chr)
  178.        col ==+ 1
  179.  
  180.     ELSE  
  181.        grprint(chr)
  182.        col ==+ 2
  183.     FI
  184.  
  185.     IF (col > 80) THEN  
  186.       PutDE(EPSON) 
  187.       linecnt ==+ 1
  188.       col = 0
  189.     FI
  190.   
  191.     cnt ==+ 1
  192.     chr = line(cnt) ; get next char
  193.   OD
  194.  
  195. PutDE(EPSON)
  196. linecnt ==+ 1
  197.  
  198. RETURN (linecnt)
  199.  
  200. ;------------------------------------
  201.  
  202. BYTE FUNC PrintBASIC(CHAR ARRAY line)
  203.  
  204. ; prints BASIC input line             
  205.  
  206. CHAR space = [32],
  207.      invsp = [160],
  208.      colon = [58],
  209.      semic = [59],
  210.      eol   = [155],
  211.      quote = [34],
  212.      comma = [44],
  213.      chr
  214.  
  215. BYTE cnt, col, tab      
  216.  
  217. BOOL inquotes   
  218.  
  219. CARD linecnt ; number of lines output
  220.  
  221. cnt = 1   ; current character in line
  222. col  = 0  ; current printer column
  223. linecnt = 0 ; lines printed
  224. inquotes = FALSE
  225.  
  226.   chr = line(cnt)
  227.   IF chr = eol THEN RETURN (0) FI
  228.  
  229.   ; drop leading spaces...
  230.  
  231.   WHILE chr = space
  232.     DO 
  233.       cnt ==+ 1
  234.       chr = line(cnt)
  235.     OD
  236.  
  237.   ; print line number...
  238.  
  239.   WHILE (chr >= '0 AND chr <= '9)
  240.     DO  
  241.       PutD(EPSON, chr)     
  242.       col ==+ 1
  243.       cnt ==+ 1
  244.       chr = line(cnt)
  245.     OD
  246.     
  247.   ; output a space...
  248.  
  249.   IF chr = space THEN
  250.     PutD(EPSON, chr)
  251.     cnt ==+ 1
  252.     chr = line(cnt)
  253.   ELSE PutD(EPSON, space)
  254.   FI
  255.  
  256.   col ==+ 1
  257.  
  258.   ; set tab...
  259.  
  260.   tab = col
  261.   
  262.   ; now print rest of line...
  263.  
  264.   WHILE chr <> eol 
  265.   DO                     
  266.     IF chr = quote THEN
  267.       IF inquotes THEN 
  268.         inquotes = FALSE 
  269.       ELSE 
  270.         inquotes = TRUE
  271.       FI
  272.     FI  
  273.  
  274.     IF ; printable character
  275.     (chr > 31 AND chr < 123 AND chr <> 96) THEN
  276.        PutD(EPSON, chr)
  277.        col ==+ 1
  278.  
  279.     ELSE  
  280.        grprint(chr)
  281.        col ==+ 2
  282.     FI
  283.  
  284.     ; should we break line?...
  285.  
  286.     IF                               
  287.     (col > 65 AND  ; close to R margin
  288.        (chr = space OR ; break line
  289.         chr = invsp OR ; at a logical
  290.         chr = comma OR ; spot if 
  291.         chr = semic))  ; possible
  292.     OR                           
  293.     (chr = colon AND inquotes = FALSE) ; separate BASIC commands
  294.     OR
  295.     (col > 80) ; unconditional line break
  296.  
  297.     ; yes...
  298.  
  299.     THEN  
  300.        PutDE(EPSON)
  301.        linecnt ==+ 1
  302.        indent(tab)
  303.        col = tab
  304.        
  305.     ; no...
  306.  
  307.     FI
  308.   
  309.     cnt ==+ 1
  310.     chr = line(cnt) ; get next char
  311.   OD
  312.  
  313. feed(2) ; end of input line
  314. linecnt ==+ 2
  315.  
  316. RETURN (linecnt)
  317.  
  318. ;-------------------------------------
  319.  
  320. PROC main()
  321.  
  322.   CHAR ARRAY source(20),
  323.              title1(75),
  324.              title2(75),
  325.              choice(10),
  326.              line(255)    
  327.  
  328.   BYTE consol = $D01F, ; start key
  329.        invflg = $2B6,  ; inverse off
  330.        shflok = $2BE,  ; shift lock
  331.        crsinh = $2F0,  ; cursor off
  332.        linecnt, linetot
  333.  
  334.   CARD page = [1] ; pages printed
  335.  
  336.   BOOL basic
  337.  
  338.   Bank = 0
  339.  
  340.   Put(125) ; clear screen
  341.   Setcolor(2,12,2)
  342.   PutE()
  343.   PrintE("    EPSON/ATASCII PRETTY PRINTER")
  344.   PrintE("       (c)1983 Leo G. Laporte")
  345.   PutE()
  346.   PrintE("  File must be LISTed BASIC or TEXT")
  347.   PutE()
  348.   Print("Enter source file > ")
  349.  
  350.   invflg = 0   ; inverse off
  351.   shflok = 64  ; caps lock
  352.   InputS(source)
  353.  
  354.   PutE()
  355.   PrintE("Enter header line #1 (max 75 chars)")
  356.   Print(">")
  357.   InputMD(KEY, title1, 75)
  358.  
  359.   PutE()
  360.   PrintE("Enter header line #2")
  361.   Print(">")
  362.   InputMD(KEY, title2, 75)
  363.  
  364.   PutE()
  365.   Print("Is this a (B)ASIC or (T)ext file? ")
  366.  
  367.   invflg = 0   ; inverse off
  368.   shflok = 64  ; caps lock
  369.   InputMD(KEY, choice, 10)
  370.   
  371.   IF choice(1) = 'T THEN
  372.     basic = FALSE
  373.   ELSE
  374.     basic = TRUE
  375.   FI
  376.  
  377.   Position(2,22)
  378.   crsinh = 1
  379.   Print("  PRESS -START- TO BEGIN PRINTING")
  380.   Position(2, 17)
  381.   
  382.   consol = 8
  383.   WHILE consol <> 6  ; wait for start
  384.     DO
  385.       consol = 0
  386.     OD
  387.  
  388.       Close(FILE) Close(EPSON)
  389.  
  390.       Open(FILE, source, 4)
  391.       Open(EPSON, "P:", 8)
  392.       
  393.       PutDE(EPSON)  
  394.       PrintD(EPSON, italics_on)
  395.       PrintDE(EPSON, title1)
  396.       PrintDE(EPSON, title2)
  397.       PrintD(EPSON,"Page ") PrintCDE(EPSON, page) 
  398.       PrintD(EPSON, italics_off)
  399.       feed(2)
  400.       linetot = 6
  401.  
  402.       InputMD(FILE, line, 255)
  403.       WHILE EOF(FILE) = FALSE
  404.         DO
  405.           IF basic THEN
  406.             linecnt = PrintBASIC(line)
  407.           ELSE
  408.             linecnt = PrintTEXT(line)
  409.           FI
  410.  
  411.           linetot ==+ linecnt
  412.           IF linetot >= MAXLINE THEN ; next page
  413.             PutD(EPSON, formfeed)
  414.             page ==+ 1
  415.             PrintD(EPSON, italics_on)
  416.             PrintDE(EPSON, title1)
  417.             PrintDE(EPSON, title2)
  418.             PrintD